package daotests;
import java.util.List;

import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.annotation.Transactional;

public class GenericSpringJpaDao<T>  extends JpaDaoSupport implements IGenericDao<T> {

    public GenericSpringJpaDao() { 
    	
    }

    @Transactional
    public void saveOrUpdate(T obj) {
        getJpaTemplate().merge(obj);
        
    }

    @Transactional
    public void delete(T obj) {
    	getJpaTemplate().remove(obj);
    }

    public T find(Class<T> clazz, Long id) {
        return getJpaTemplate().find(clazz, id);
    }

    public List<T> findAll(Class<T> clazz) {
        return getJpaTemplate().find("from " + clazz.getName());
    }
}
